* Project      :  The Full, Persistent, and Symmetric Pass-Through of a Temporary VAT Cut
* Authors      :  Márcia Silva-Pereira, João Quelhas, Tiago Bernardino, Ricardo Duque Gabriel
* Date         :  01/04/2025
* Description  :  Event-study Regression
* Dependencies :
* Modifications: (add date, author and change)

*********************************************************
*                Event-study Regression                 *
*********************************************************

local vce_cluster ${vce_cluster}
local weights ${weights}
local variable ${variable}
local aggregation ${aggregation}
	
// Load the cleaned dataset.
use "${path_work}/auxiliar/imputation_0_only_food.dta", clear

collapse (${aggregation}) ${variable} (first) ecoicop5 treatment weight, by (id_sm five_day_number)

// Compute a price index with base in the day before policy announcement I.
local   base_date 22
egen    base_price_23032023 = total(${variable}/ (five_day_number == `base_date')), by(id_sm)
gen     index_23032023 = (${variable}/ base_price_23032023) * 100

xtset id_sm five_day_number

file open  myfile using "${results_figures}/temp_file_implementation.txt", write text replace
file write myfile "lower_ci, coefficient, upper_ci" _n _n
file close myfile

file open  myfile using "${results_figures}/temp_file_reversal.txt", write text replace
file write myfile "lower_ci, coefficient, upper_ci" _n _n
file close myfile

*********************************************************

* FIGURE 4: Pass-Through Estimates of the 2023 Temporary VAT Cut in Portugal
*********************************************************

preserve

// Keep the data around the event.
keep if five_day_number >= 17
keep if five_day_number <= 32

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 23

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) window(${window_low} ${window_high}) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)
local z = 1.96

file open  myfile using "${results_figures}/temp_file_implementation.txt", write text append

scalar coef = results[1,10]
scalar se   = sqrt(vcv[10,10])

generate coeff = coef
generate z = `z'
generate see = se
scalar lb = coeff - z * see
generate lbb = lb
scalar ub = coeff + z * see
generate ubb = ub
format %12.0g coeff lbb ubb
file write myfile "total, " (lbb) ", " (coeff) ", " (ubb) _n _n
drop coeff z see lbb ubb

file close myfile

// Make the plot with the results.
xteventplot, ytitle("Percentage change") xtitle("5-day Periods to Event") ///
	nosupt scatterplotopts(lcolor(dknavy) recast(connected) mcolor(dknavy) ///
	msymbol(circle)) ciplotopts(recast(rarea) mcolor(black) fcolor(dknavy*0.2)) ///
	graphregion(fcolor(white)) yscale(lcolor(black) lwidth(none) line) ///
	tscale(lcolor(black) lwidth(none) line) ylabel(-10(2)2) ///
	yline(-5.66, lcolor("dknavy") lpattern(dash) lwidth(medthin)) ///
	text(-6.2 -4.8 "100% Pass-Through", color("dknavy") placement(e)) ///
	xline(0, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(-9.5 0.1 "Announcement", color("gray") placement(e)) ///
	xline(5, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(-9.5 5 "Implementation", color("gray") placement(e))
	
// Save the coefficients.
outreg2 using "${results_figures}/figure_4.txt", replace

// Export the graph.
graph export "${results_figures}/figure_4.png", as(png) replace width(2400) height(1372)

*********************************************************


* FIGURE A.5: Pass-Through Estimates of the 2023 Temporary VAT Cut in Portugal (A) Linear Trend Extrapolation
*********************************************************

// Make the plot with the results.
xteventplot, overlay(trend) ytitle("Percentage change") xtitle("5-day Periods to Event") ///
	scatterplotopts(lcolor(dknavy) recast(connected) mcolor(dknavy) ///
	msymbol(circle)) ciplotopts(recast(rarea) mcolor(black) fcolor(dknavy*0.2)) ///
	graphregion(fcolor(white)) yscale(lcolor(black) lwidth(none) line) ///
	tscale(lcolor(black) lwidth(none) line) ylabel(-10(2)2) ///
	yline(-5.66, lcolor("dknavy") lpattern(dash) lwidth(medthin)) ///
	text(-6.2 -4.8 "100% Pass-Through", color("dknavy") placement(e)) ///
	xline(0, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(-9.5 0.1 "Announcement", color("gray") placement(e)) ///
	xline(5, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(-9.5 5 "Implementation", color("gray") placement(e))
	
// Export the graph.
graph export "${results_figures}/figure_a5a.png", as(png) replace width(2400) height(1372)

restore

*********************************************************


* FIGURE 6: Pass-Through Estimates of the 2023 Temporary VAT Cut Reversion in Portugal
*********************************************************

preserve

// Keep the data around the event.
keep if five_day_number >= 60
keep if five_day_number <= 83

// Policy variable: 1 after the reference date.
replace treatment = 0 if five_day_number < 66

if ${weights} == 0 {

// Run the event-study regression.
xtevent index_23032023, policyvar(treatment) panelvar(id_sm) timevar(five_day_number) ///
window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
	
}

if ${weights} == 1 {

// Run the event-study regression.
xtevent index_23032023 [pweight = weight], policyvar(treatment) panelvar(id_sm) timevar(five_day_number) ///
window(${window_low} 16) vce(cluster ${vce_cluster}) impute(nuchange) reghdfe trend(${trend}, method(gmm) saveoverlay)
		
}

matrix results = r(delta)
matrix vcv = r(Vdelta)
local z = 1.96

file open  myfile using "${results_figures}/temp_file_reversal.txt", write text append

scalar coef = results[1,19]
scalar se   = sqrt(vcv[19,19])
generate coeff = coef
generate z = `z'
generate see = se
scalar lb = coeff - z * see
generate lbb = lb
scalar ub = coeff + z * see
generate ubb = ub
format %12.0g coeff lbb ubb
file write myfile "total, "(lbb) ", " (coeff) ", " (ubb) _n _n
drop coeff z see lbb ubb

file close myfile

// Make the plot with the results.
xteventplot, ytitle("Percentage change") xtitle("5-day Periods to Event") ///
	nosupt scatterplotopts(lcolor(dknavy) recast(connected) mcolor(dknavy) ///
	msymbol(circle)) ciplotopts(recast(rarea) mcolor(black) fcolor(dknavy*0.2)) ///
	graphregion(fcolor(white)) yscale(lcolor(black) lwidth(none) line) ///
	tscale(lcolor(black) lwidth(none) line) ylabel(-2(2)12) ///
	yline(6, lcolor("dknavy") lpattern(dash) lwidth(medthin)) ///
	text(5.4 -4.8 "100% Pass-Through", color("dknavy") placement(e)) ///
	xline(0, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(11.5 0.1 "Announcement", color("gray") placement(e)) ///
	xline(14, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(11.5 11.8 "Reversal", color("gray") placement(e))

// Save the coefficients.
outreg2 using "${results_figures}/figure_6.txt", replace

// Export the graph.
graph export "${results_figures}/figure_6.png", as(png) replace width(2400) height(1372)

*********************************************************


* FIGURE A.7: Pass-Through Estimates of a Temporary VAT Cut (A) Linear Trend Extrapolation
*********************************************************

// Make the plot with the results.
xteventplot, overlay(trend) ytitle("Percentage change") xtitle("5-day Periods to Event") ///
	scatterplotopts(lcolor(dknavy) recast(connected) mcolor(dknavy) ///
	msymbol(circle)) ciplotopts(recast(rarea) mcolor(black) fcolor(dknavy*0.2)) ///
	graphregion(fcolor(white)) yscale(lcolor(black) lwidth(none) line) ///
	tscale(lcolor(black) lwidth(none) line) ylabel(-2(2)10) ///
	yline(6, lcolor("dknavy") lpattern(dash) lwidth(medthin)) ///
	text(5.4 -4.8 "100% Pass-Through", color("dknavy") placement(e)) ///
	xline(0, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(9.5 0.1 "Announcement", color("gray") placement(e)) ///
	xline(14, lcolor("gray*0.5") lpattern(solid) lwidth(medthin)) ///
	text(9.5 11.8 "Reversal", color("gray") placement(e))

// Export the graph.
graph export "${results_figures}/figure_a7a.png", as(png) replace width(2400) height(1372)

restore

********************************************************************************
